{% extends "orga/mails/base.html" %}

{% load i18n %}

{% block mail_content %}
    <div class="d-md-flex justify-content-between">
        <h2>
            <span>
                {{ page_obj.paginator.count }}
                {% blocktranslate trimmed count count=page_obj.paginator.count %}
                    pending mail
                {% plural %}
                    pending mails
                {% endblocktranslate %}
            </span>
        </h2>
        {% include "orga/event/component_link.html" %}
    </div>
    <div class="submit-group">
        <div>
            {% include "common/includes/search_form.html" with omit_wrapper=True %}
        </div>
        <div class="d-flex flex-column align-items-end">
            <div>
                {% if is_paginated and page_obj.paginator.num_pages > 1 %}
                    <a href="{{ request.event.orga_urls.send_outbox }}?pks={% for mail in mails %}{{ mail.pk }}{% if not forloop.last %},{% endif %}{% endfor %}">
                        <button class="btn btn-outline-success">{% translate "Send all on this page" %}</button>
                    </a>
                {% endif %}
                <a href="{{ request.event.orga_urls.send_outbox }}?{{ request.GET.urlencode }}" class="btn btn-success">
                    {% translate "Send all" %}
                </a>
                <a href="{{ request.event.orga_urls.purge_outbox }}?{{ request.GET.urlencode }}" class="btn btn-danger">
                    {% translate "Discard all" %}
                </a>
            </div>
            <div>
                {% if is_filtered %}
                    <div class="text-right text-muted mt-2">
                        <i class="fa fa-filter"></i>
                        {% translate "The current filters will be used when sending/discarding emails." %}
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
    <div class="table-responsive-sm">
        <table class="table table-sm table-flip table-sticky">
            <thead>
                <tr>
                    <th>
                        {{ phrases.base.email_subject }}
                        <a href="{% querystring sort="subject" %}"><i class="fa fa-caret-down" title="{% translate "Sort (a-z)" %}"></i></a>
                        <a href="{% querystring sort="-subject" %}"><i class="fa fa-caret-up" title="{% translate "Sort (z-a)" %}"></i></a>
                    </th>
                    <th>
                        {% translate "To" %}
                        <a href="{% querystring sort="to" %}"><i class="fa fa-caret-down" title="{% translate "Sort (a-z)" %}"></i></a>
                        <a href="{% querystring sort="-to" %}"><i class="fa fa-caret-up" title="{% translate "Sort (z-a)" %}"></i></a>
                    </th>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for mail in mails %}
                    <tr>
                        <td>
                            <a href="{{ mail.urls.base }}">{{ mail.subject }}</a>
                        </td>
                        <td>
                            {% for user in mail.to_users.all %}
                                {% if user in request.event.submitters %}
                                    <a href="{% url "orga:speakers.view" event=request.event.slug code=user.code %}">
                                        {{ user }}
                                    </a>{% else %}{{ user }}{% endif %}{% if not forloop.last or mail.to %}, {% endif %}
                            {% endfor %}
                            {% if mail.to %}{{ mail.to }}{% endif %}
                        </td>
                        <td>
                            {% for submission in mail.submissions.all %}
                                <div class="d-flex align-items-center">
                                    {% if show_tracks and submission.track %}
                                        <div class="color-square" style="background-color: {{ submission.track.color }}" title="{{ submission.track.name }}">
                                        </div>
                                    {% endif %}
                                    <a href="{{ submission.orga_urls.base }}">
                                        {{ submission.title }}
                                    </a>
                                </div>
                            {% endfor %}
                        </td>
                        <td class="text-right">
                            {% if mail.attachments %}
                                <i class="fa fa-paperclip" title="{% translate "Contains an attachment" %}"></i>
                            {% endif %}
                            {% include "orga/includes/mail_template_role.html" with template=mail.template %}
                        </td>
                        <td class="action-column">
                            <a href="{{ mail.urls.send }}" title="{{ phrases.base.send }}" class="btn btn-sm btn-success">
                                <i class="fa fa-mail-forward"></i>
                            </a>
                            <a href="{{ mail.urls.edit }}" title="{{ phrases.base.edit }}" class="btn btn-sm btn-info">
                                <i class="fa fa-edit"></i>
                            </a>
                            <a href="{{ mail.urls.delete }}" title="{{ phrases.base.delete_button }}" class="btn btn-sm btn-danger">
                                <i class="fa fa-trash"></i>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% include "orga/includes/pagination.html" %}

{% endblock mail_content %}
